<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus" v-has="'agency:add'">新增</a-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" v-has="'agency:delete'" />删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :scroll="{ x: 'auto' }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <!-- 状态 -->
        <template slot="status" slot-scope="text, record">
          <a-switch
            default-checked
            :checked="record.status"
            @click="statusEditChange(record, record.status, 'status')"
          />
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'agency:edit'">编辑</a>
          <a-divider type="vertical" v-has="'agency:edit'" />
          <a-dropdown v-has="'agency:delete'">
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <xhdjAgency-modal ref="modalForm" @ok="modalFormOk" :all="this.all"></xhdjAgency-modal>
    <!-- 表单区域 -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import XhdjAgencyModal from './modules/XhdjAgencyModal'
import Area from '@/components/_util/Area'
import { getFileAccessHttpUrl } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction } from '@/api/manage'
import Speech from 'speak-tts'
export default {
  name: 'XhdjAgencyList',
  mixins: [JeecgListMixin],
  components: {
    XhdjAgencyModal,
  },
  data() {
    return {
      speech: null,
      description: '服务配置表',
      queryParam: {
        agencyCode: '',
        province: undefined,
        area: undefined,
        city: undefined,
      },
      // 表头
      columns: [
        {
          title: '等级',
          align: 'center',
          dataIndex: 'levelName',
        },
        {
          title: '业绩',
          align: 'center',
          dataIndex: 'amount',
        },
        {
          title: '抽成比例',
          align: 'center',
          dataIndex: 'rate',
          customRender: (text, record) => {
            return record.rate + ' %'
          },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' },
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/xhdjAgencyLevel/list',
        delete: '/xhdjAgencyLevel/delete',
        deleteBatch: '/xhdjAgency/deleteBatch',
        exportXlsUrl: 'xhdjAgency/exportXls',
        importExcelUrl: 'xhdjAgency/importExcel',
      },
      all: [], // 地址信息
      allList: [], // 省份数据
      citys: [],
      cityss: [],
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  created() {

  },
  methods: {
    getAvatarView: function (avatar) {
      return getFileAccessHttpUrl(avatar)
    },
    statusEditChange(record, value, type) {
      record[type] = value == 0 ? 1 : 0
      httpAction('/xhdjAgencyLevel/edit', record, 'put')
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loadData()
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.ant-row {
  display: flex;
}
</style>
